package com.aegis.core.dao;

import com.aegis.core.model.HashScanResult;
import com.aegis.core.model.ScanResult;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

/**
 * @Author wuweixin
 *
 * @Version 1.0
 * @Descritube
 */
public interface AegisDao {

    // ============================= Common =============================

    Object getObject(String key);

    Object getAndDel(String key);

    void del(String key);

    boolean setObject(String key, Object value);

    boolean setObject(String key, Object value, long time);

    boolean setObject(String key, Object value, long time, TimeUnit timeUnit);

    long incr(String key, long delta);

    long decr(String key, long delta);

    // ============================= Hash =============================

    Object hget(String key, String item);

    Map<Object, Object> hmget(String key);

    boolean hmset(String key, Map<String, Object> map);

    boolean hmset(String key, Map<String, Object> map, long time);

    boolean hset(String key, String item, Object value);

    boolean hset(String key, String item, Object value, long time);

    void hdel(String key, Object... item);

    boolean hHasKey(String key, String item);

    double hincr(String key, String item, double by);

    double hdecr(String key, String item, double by);

    <T> void scanHash(String key, int count, String pattern, Function<HashScanResult<T>, Boolean> function);

    // ============================= Set =============================

    Set<Object> sGet(String key);

    boolean sHasKey(String key, Object value);

    long sSet(String key, Object... values);

    long sSetAndTime(String key, long time, Object... values);

    long sGetSetSize(String key);

    long setRemove(String key, Object... values);

    // ============================= Keys =============================


    /**
     * 执行 Lua 脚本
     *
     * @param script Lua 脚本内容
     * @param keys   KEYS 参数列表
     * @param args   ARGV 参数列表
     * @return 执行结果
     */
    Object eval(String script, List<String> keys, List<String> args);
}